﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;

namespace WinformText0001
{
    class DbHelper
    {
        private static string conString = "server=.;database=Blogs;uid=sa;pwd=lz20001130";

        public static DataTable GetDataTable(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);

            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql,sqlConnection);

            sqlConnection.Open();

            DataTable dt = new DataTable();

            dataAdapter.Fill(dt);

            return dt;


        }

        public static int AddOrUpDateOrDelete(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);

            SqlCommand sqlCommand = new SqlCommand(sql,sqlConnection);

            sqlConnection.Open();

            return sqlCommand.ExecuteNonQuery();
           
        }
    }
}
